﻿@page "/cascading-dropdowns"

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<h1>Cascading DropDowns</h1>

<p>Cascading Radzen Blazor DropDown components.</p>

<RadzenExample Name="CascadingDropDowns" Heading="false" Documentation="false">
<h3>Customers</h3>
<RadzenDropDown TValue="string" @bind-Value="CustomerID" Placeholder="Select customer" AllowFiltering="true" Data="@(customers)" TextProperty="CompanyName" ValueProperty="CustomerID" Style="margin-bottom: 20px" />
<br />
<h3>Orders</h3>
<RadzenDropDown TValue="int" @bind-Value="OrderID" Placeholder="Select order" Data="@(orders.Where(o => o.CustomerID == CustomerID))" ValueProperty="OrderID" Style="margin-bottom: 20px">
    <Template>
        Order Date: @String.Format("{0:d}", ((Order)context).OrderDate)
    </Template>
</RadzenDropDown>
<br />
<h3>Order Details</h3>
<RadzenDataGrid AllowFiltering="true" AllowPaging="true" AllowSorting="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" 
            Data="@(orderDetails.Where(o => o.OrderID == OrderID))" TItem="OrderDetail" ColumnWidth="200px">
    <Columns>
        <RadzenDataGridColumn TItem="OrderDetail" Property="Product.ProductName" Title="Product" />
        <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" />
        <RadzenDataGridColumn TItem="OrderDetail" Property="Discount" Title="Discount" FormatString="{0:P}" />
    </Columns>
</RadzenDataGrid>
<br />
</RadzenExample>
@code {
    IEnumerable<Customer> customers;
    IEnumerable<Order> orders;
    IEnumerable<OrderDetail> orderDetails;

    string CustomerID;
    int OrderID;

    protected override void OnInitialized()
    {
        customers = dbContext.Customers.ToList();
        orders = dbContext.Orders.ToList();
        orderDetails = dbContext.OrderDetails.Include("Product").ToList();
    }
}
